import React, {Component} from 'react';
import {StyleSheet, Text, View} from 'react-native';
import {connect} from "react-redux";
import actions from "../action";

class FavoritePage extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>FavoritePage</Text>
        <Text
          onPress={() => {
            this.props.onThemeChange('#096')
          }}
        >变更主题</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  }
});

/**
 * 映射state
 * @param state
 */
const mapStateToProps = state => ({
  theme: state.theme.theme
});
/**
 * 映射dispatch
 * @param dispatch
 * @returns {{onThemeChange: function(*=): *}}
 */
const mapDispatchToProps = dispatch => ({
  onThemeChange: theme => dispatch(actions.onThemeChange(theme))
});
/**
 * 连接 React组件 与 Redux Store
 */
export default connect(mapStateToProps, mapDispatchToProps)(FavoritePage)
